home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / jaz_clib.arc / JZEDTCHR.DMO < prev    next >
Text File  |  1989-04-09  |  9KB  |  325 lines

  1. /*
  2. ┌────────────────────────────────────────────────────────────────────────────┐
  3. │jzedtchr.dmo                                     │
  4. │Allow editing of a character set which can be loaded to replace the original│
  5. │                                         │
  6. │Usage: jzedtchr <filename>                             │
  7. │                                         │
  8. │This program allows you to edit/Create a custom character set. It is a demo │
  9. │of some of the library routines that I have written including and interrupt │
  10. │driven clock routine.                                 │
  11. │                                         │
  12. │ (C) JazSoft Software by Jack A. Zucker (301) 794-5950              │
  13. └────────────────────────────────────────────────────────────────────────────┘
  14. */
  15.  
  16.  
  17. #include <jaz.h>        /* define misc structs and macros */
  18. #include <keys.h>        /* define scan codes */
  19. #include <jzscreen.h>        /* define colors */
  20. #include <gscreen.h>        /* define global header record */
  21. #include <fcntl.h>        /* file stuff */
  22.  
  23.  
  24. TVECTOR gvec;                  /* vector to hold old clock int */
  25. int clock();            /* clock interrupt routine */
  26. gcount = 17;            /* count of clock tics       */
  27. int MONO = 1;
  28. char G_FILENAME[50];        /* hold global file name */
  29.  
  30. static char *help[] = {
  31.   "Clear Bit            F1 | Space",
  32.   "Set Bit              F2",
  33.   "First Char         HOME",
  34.   "Last Char           END",
  35.   "Next Char          PGDN",
  36.   "Prev Char          PGUP",
  37.   "Quick Next    CTRL-PGDN",
  38.   "Quick Prev    CTRL-PGUP",
  39.   "View Char Set     ALT-V",
  40.   "Quit w/o Saving     ESC",
  41.   "Save and Quit     ALT-S",
  42.   ""
  43. };
  44.  
  45. #define CHARLEN 8        /* 8 bytes for each character */
  46. #define NUMCHARS 128        /* number of chars in table */
  47. #define TABLELEN NUMCHARS * CHARLEN /* number of bytes in the character table */
  48. #define MONOATTR 7        /* light gray on black background */
  49. #define COLORATTR 31        /* white letters on YELLOW back */
  50. #define G_ROW 8         /* starting row           */
  51. #define G_COL 35        /* starting column          */
  52. #define S_IWRITE 0000200    /* write permission, owner */
  53. #define TIMER 0x1c        /* timer interrupt          */
  54. #define COPYWRITE "JZEDTCHR (C) JazSoft 1986 by Jack A. Zucker @ 301-794-5950 |\
  55.  CIS: 75766,1336"
  56.  
  57. #define GMENU GREEN
  58. #define GWND  CYAN
  59. #define GLOGO YELLOW
  60. #define GCHAR MAGENTA
  61. #define GHEADING RED
  62.  
  63. #if DEBUG
  64.   char wtable[TABLELEN];
  65. #endif
  66.  
  67. main(argc,argv)
  68. int argc;
  69. char **argv;
  70. {
  71.  
  72.   #if ! DEBUG
  73.   char wtable[TABLELEN];        /* hold the table entries */
  74.   #endif
  75.   int whandle;                /* file handle          */
  76.   int w,wch,wscan;
  77.  
  78.   jzlogo();            /* display logo on screen */
  79.  
  80.   strcpy(G_FILENAME,*(++argv));     /* copy possible file name */
  81.  
  82.   if (! G_FILENAME[0] ) {        /* no file name specified */
  83.     jzscrprn("Filename: ",24,0,GREEN);
  84.     wch = jzinstr(G_FILENAME,35,24,10,CYAN,60L,"\001");
  85.     if (wch == 27 || (! G_FILENAME[0])) exit(0);
  86.   }
  87.  
  88.   if ((whandle = open(G_FILENAME,0)) == -1)
  89.     /* copy rom character set to work storage */
  90.     movedata(0xF000,0xFA6E,getds(),wtable,TABLELEN);
  91.   else {
  92.     read(whandle,wtable,TABLELEN);    /* read saved char set into buffer */
  93.     close(whandle);
  94.   }
  95.  
  96.   MONO = MEMB(0x40,0x49) == 7;        /* get screen type */
  97.  
  98.   cls(7);                /* clear the display screen */
  99.  
  100.   jzscrprn(COPYWRITE,0,2,GLOGO);
  101.  
  102.   jzdrwbox(G_ROW , G_COL , 10 , 10 ,GWND);   /* draw box for characters */
  103.  
  104.   jzscrprn("     Edit Keys",2,0,GHEADING);
  105.  
  106.   for (w = 0 ; *help[w] ; w ++)
  107.     jzscrprn(help[w],w+5,0,GMENU);
  108.  
  109.   jzgetint(TIMER,&gvec);
  110.   jzinsint(TIMER,clock);
  111.  
  112.   jzscrprn("Editing:",23,0,LIGHTGRAY);
  113.   jzscrprn(G_FILENAME,23,9,BROWN);
  114.  
  115.   if (editchar(wtable)) {              /* edit character table */
  116.     if ((whandle = creat(G_FILENAME,S_IWRITE)) == -1) {
  117.       printf("Trouble opening %s",G_FILENAME);
  118.       exit(0);
  119.     }
  120.     write(whandle,wtable,TABLELEN);
  121.     close(whandle);
  122.   }
  123.  
  124.   jzsetint(TIMER,gvec);
  125.  
  126.   if (MONO) {
  127.     cls(7);
  128.     printf("\nCan't view character set without color graphics adapter!");
  129.     exit();
  130.   }
  131.  
  132.   viewchar(wtable);        /* view character set  */
  133.  
  134.   jzloccur(23,0);        /* end program neatly  */
  135.  
  136. }
  137.  
  138. viewchar(ftable)
  139. char *ftable;
  140. {
  141.   int w1,w2,wscan;
  142.   long far *biostable = (long far *) 0x7C; /* pointer to extended char table */
  143.   long tablesave;               /* save original address */
  144.   TWINDOW *wptr,*jzappend();
  145.  
  146.   tablesave = *biostable;    /* save original character table */
  147.  
  148.   /* Now change the extended character table pointer to point to our new */
  149.   /* character set */
  150.  
  151.   *biostable = (long) ((long) getds() << 16 | (int) ftable);
  152.  
  153.   wptr = jzappend(&g_header,31,0,0,25,80);    /* save current screen */
  154.  
  155.   jzsetmde(6);            /* go into graphics mode */
  156.  
  157.   w1 = 0;
  158.   while (w1 <= 112) {
  159.     for (w2 = 0 ; w2 < 16 ; w2 ++)
  160.       printf("%-4c",(w1+w2) + 128);
  161.     printf("\n");
  162.     w1 += 16;
  163.   }
  164.   printext("\n\n(C) JazSoft 1986 by Jack A. Zucker @ 301-794-5950");
  165.   printext("\n10318 Broom Lane");
  166.   printext("\nSeabrook Md, 20706");
  167.   printext("\nFor info regarding source code, please feel free to call");
  168.   printext("\nor send $25.00 for over 100 source and obj files for MS/C !");
  169.   printext("\n-Jaz");
  170.   printext("\n\nPress <Enter> (\177) to Continue...");
  171.  
  172.   do ; while (jzinkey(&wscan) != 13);
  173.  
  174.   *biostable = tablesave;        /* restore original pointer */
  175.  
  176.   jzsetmde(3);                /* back to color graphics mode */
  177.  
  178.   jzrstwnd(wptr);            /* restore original screen */
  179.  
  180.   free ((int *) wptr->buf);        /* free up buffer memory */
  181.  
  182.   exit(0);
  183.  
  184. }
  185.  
  186. int editchar(ftable)
  187. char *ftable;
  188. {
  189.   int wscan,wch;
  190.   int wcol,wrow;
  191.   int windex = 0;
  192.  
  193.   wcol = G_COL + 1;
  194.   wrow = G_ROW + 1;
  195.  
  196.   displaychar(ftable+windex);
  197.   do {
  198.     jzloccur(G_ROW - 1,G_COL + 1);
  199.     printf("Char %003d",windex / CHARLEN);
  200.     jzloccur(wrow,wcol);            /* position the cursor */
  201.     if ((wch = jzinkey(&wscan)))
  202.       switch (wch) {                /* look for esc key - end */
  203.     case ESC : return(0);
  204.     case 32  : jzwrtchr(' ',GCHAR,1);
  205.            wcol = min(wcol + 1,43);
  206.            break;
  207.       }
  208.     else
  209.       switch (wscan) {
  210.     case ALT_S:
  211.           savechar(ftable + windex);
  212.           return(-1);
  213.     case ALT_V:
  214.           if (! MONO) {
  215.             savechar(ftable + windex);
  216.             jzsetint(TIMER,gvec);  /* temporarily turn off clock */
  217.             viewchar(ftable);
  218.             gcount = 17;
  219.             jzinsint(TIMER,clock); /* turn clock back on */
  220.           }
  221.           break;
  222.     case F1 : jzwrtchr(' ',GCHAR,1);
  223.           wcol = min(wcol + 1,43);
  224.           break;
  225.     case F2 : jzwrtchr('▒',GCHAR,1);
  226.           wcol = min(wcol + 1,43);
  227.           break;
  228.     case UARR: wrow = max(9,wrow-1);
  229.            break;
  230.     case DARR: wrow = min(16,wrow+1);
  231.            break;
  232.     case LARR: wcol = max(36,wcol-1);
  233.            break;
  234.     case RARR: wcol = min(43,wcol+1);
  235.            break;
  236.     case CTRL_PGUP:
  237.            savechar(ftable + windex);
  238.            windex = max(0,windex - CHARLEN * CHARLEN);
  239.            displaychar(ftable+windex);
  240.            break;
  241.     case CTRL_PGDN:
  242.            savechar(ftable + windex);
  243.            windex = min(windex + CHARLEN * CHARLEN,TABLELEN - CHARLEN);
  244.            displaychar(ftable+windex);
  245.            break;
  246.     case HOME: savechar(ftable + windex);
  247.            windex = 0;
  248.            displaychar(0);
  249.            break;
  250.     case END:  savechar(ftable + windex);
  251.            windex = TABLELEN - CHARLEN;
  252.            displaychar(ftable +TABLELEN - CHARLEN);
  253.            break;
  254.     case PGUP: savechar(ftable + windex);
  255.            windex = max(0,windex - CHARLEN);
  256.            displaychar(ftable+windex);
  257.            break;
  258.     case PGDN: savechar(ftable + windex);
  259.            windex = min(windex + CHARLEN,TABLELEN - CHARLEN);
  260.            displaychar(ftable+windex);
  261.            break;
  262.       }
  263.   } while (-1);
  264. }
  265.  
  266. displaychar(fchar)
  267. char *fchar;
  268. {
  269.   int wcol,wrow;
  270.   char wchar;
  271.  
  272.   for (wrow = 0 ; wrow < 8 ; wrow ++) {     /* loop through chars in table */
  273.     wchar = *(fchar+wrow);           /* point to next character */
  274.     for (wcol = 7 ; wcol >= 0 ; wcol --) {  /* loop through 8 bits    */
  275.       jzloccur(9+wrow,36+wcol);
  276.       jzwrtchr(wchar & 1 ? '▒' : ' ',GCHAR,1);
  277.       wchar >>= 1;
  278.     }
  279.   }
  280. }
  281.  
  282. savechar(fchar)
  283. char *fchar;
  284. {
  285.   int wcol,wrow;
  286.   unsigned char wbit;
  287.   char wstr[9];
  288.  
  289.   for (wrow = 0 ; wrow < 8 ; wrow ++) {
  290.     jzredscr(wstr,wrow + G_ROW + 1,G_COL + 1,8); /* read one line from screen */
  291.     *fchar = 0;                  /* init to all zeros */
  292.     wbit = 128;                  /* set 8th bit       */
  293.     for (wcol = 0 ; wcol < 8 ; wcol ++) {
  294.       if (wstr[wcol] != 32) *fchar |= wbit;
  295.       wbit >>= 1;
  296.     }
  297.     fchar++;
  298.   }
  299. }
  300.  
  301. clock()
  302. {
  303.    char wstr[9];
  304.    if (gcount >= 17) {
  305.      jzbiostm(wstr);
  306.      jzscrprn(wstr,2,71,GHEADING);
  307.      gcount = 0;
  308.    }
  309.    else
  310.      gcount ++;
  311. }
  312.  
  313. printext(fstr)
  314. char *fstr;
  315. {
  316.   while (*fstr)
  317.     if (*fstr != '\n')
  318.       printf("%c",(unsigned char) (*fstr++) | 0x80);
  319.     else {
  320.       printf("\n");
  321.       fstr++;
  322.     }
  323. }
  324.  
  325.